center box: implement GtkBuildable
authorMatthias Clasen <mclasen@redhat.com>
Sat, 3 Jun 2017 20:04:57 +0000 (16:04 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Jun 2017 01:21:00 +0000 (21:21 -0400)
Make it possible to fill the slots by using the
type attribute on child nodes. This is necessary
since GtkCenterBox does not derive from GtkContainer.

gtk/gtkcenterbox.c

index 91a7a0477f43355894cdc5125453262777a915f1..1a19fa1b87c79ce0c1edbb1c482d5c0056310be3 100644 (file)
@@ -46,6 +46,7 @@
 #include "gtkcenterbox.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkwidgetprivate.h"
+#include "gtkbuildable.h"
 
 struct _GtkCenterBox
 {
@@ -63,8 +64,33 @@ struct _GtkCenterBoxClass
 };
 
 
-G_DEFINE_TYPE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET);
+static void gtk_center_box_buildable_init (GtkBuildableIface *iface);
 
+G_DEFINE_TYPE_WITH_CODE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET,
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                                gtk_center_box_buildable_init))
+
+static void
+gtk_center_box_buildable_add_child (GtkBuildable  *buildable,
+                                    GtkBuilder    *builder,
+                                    GObject       *child,
+                                    const gchar   *type)
+{
+  if (g_strcmp0 (type, "start") == 0)
+    gtk_center_box_set_start_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
+  else if (g_strcmp0 (type, "center") == 0)
+    gtk_center_box_set_center_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
+  else if (g_strcmp0 (type, "end") == 0)
+    gtk_center_box_set_end_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
+  else
+    GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_CENTER_BOX (buildable), type);
+}
+
+static void
+gtk_center_box_buildable_init (GtkBuildableIface *iface)
+{
+  iface->add_child = gtk_center_box_buildable_add_child;
+}
 
 static void
 gtk_center_box_measure (GtkWidget      *widget,